package com.ouyeel.wlxer.activity;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ouyeel.wlxer.R;
import com.ouyeel.wlxer.base.BaseActivity;
import com.ouyeel.wlxer.base.TypeItem;
import com.ouyeel.wlxer.util.MyPopupWindow;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.BindViews;

/**
 * Created by rankaifeng on 2017/11/17.
 */

public class QuoteActivity extends BaseActivity implements View.OnClickListener, MyPopupWindow.ListViewOnitemClick {
    @BindView(R.id.tv_quote_time)
    TextView tvQuoteTime;
    @BindView(R.id.tv_quote_alltype)
    TextView tvQuoteAlltype;
    @BindView(R.id.tv_quote_line)
    TextView tvQuoteLine;
    @BindViews({R.id.rel_quote_time, R.id.rel_quote_alltype, R.id.rel_quote_line})
    List<RelativeLayout> relativeLayouts;
    @BindView(R.id.lin_quote_top)
    LinearLayout linQuoteTop;
    MyPopupWindow myPopupWindow;
    List<TypeItem> typeItemList;

    @Override
    public int getLayout() {
        return R.layout.quote_activity;
    }

    @Override
    public void initView() {
        showTitleAndLeftBack("我要报价");
        myPopupWindow = new MyPopupWindow();
        myPopupWindow.setListViewOnitemClick(this);
        for (int i = 0; i < relativeLayouts.size(); i++) {
            relativeLayouts.get(i).setOnClickListener(this);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rel_quote_time:
                getTypeAndLines("时间");
//                myPopupWindow.pWindowDisOrShow(this, "", linQuoteTop);
                break;
            case R.id.rel_quote_alltype:
                getTypeAndLines("类型");
//                myPopupWindow.pWindowDisOrShow(this, "", linQuoteTop);
                break;
            case R.id.rel_quote_line:
                getTypeAndLines("线路");
//                myPopupWindow.pWindowDisOrShow(this, "", linQuoteTop);
                break;
        }
    }

    private void getTypeAndLines(String str) {
        TypeItem typeItem;
        typeItemList = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            typeItem = new TypeItem();
            typeItem.setTitle(str + i);
            typeItemList.add(typeItem);
        }
        myPopupWindow.pWindowDisOrShow(this, typeItemList, linQuoteTop);
    }

    /**
     * popupwindow的item点击事件
     *
     * @param view
     * @param position
     */
    @Override
    public void onItemClickListener(View view, int position) {
        showTost(typeItemList.get(position).getTitle());
    }
}
